package com.example.demo.service.impl;

import com.example.demo.config.MsgType;
import com.example.demo.message.Message;
import com.example.demo.request.WxRequest;
import com.example.demo.service.EventService;
import com.example.demo.service.MainService;
import com.example.demo.service.TextService;
import com.example.demo.util.XmlUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MainServiceImpl implements MainService {

    @Resource
    private EventService eventService;

    @Resource
    private TextService textService;

    @Override
    public String getMessage(WxRequest wxRequest) {
        System.out.println(wxRequest);
        Message message = new Message();

        String msgType = wxRequest.getMsgType();
        //根据不同的类型进行不同的处理

        //事件类型处理
        if(MsgType.EVENT.equals(msgType)){
            message = eventService.getTextMessage(wxRequest);
        }

        //文字类型处理
        if(MsgType.TEXT.equals(msgType)){
            message = textService.getTextMessage(wxRequest);
        }

        return XmlUtil.toXml(message);
    }

}
